package com.github.cyf.interceptor.page;

import lombok.Data;
import java.util.List;

/**
 * @author chenyifan
 * @create 2024-04-13 18:21
 */
@Data
public class PageInfo<T> {
    /**
     * 当前页码
     */
    private int pageNo;

    /**
     * 页面大小
     */
    private int pageSize;

    /**
     * 总记录数
     */
    private int total;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 是否首页
     */
    private boolean isFirst;
    /**
     * 是否尾页
     */
    private boolean isEnd;

    public PageInfo() {
    }

    public PageInfo(List<T> list) {
        Page page = (Page) list;
        this.pageNo = page.getPageNo();
        this.pageSize = page.getPageSize();
        this.total = page.getTotal();
        this.totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
        this.isFirst = pageNo == 1;
        this.isEnd = pageNo == totalPage;
    }

}
